package com.etc.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.etc.pojo.Student;

public interface StudentMapper {
    // 综合查询
    @Select("<script> select s_id id, s_name sname, s_birth birthday, s_sex sex from mz_student"
            + " where 1 = 1  "
            // if  test=“ognl 不用写#$”
            + " <if test='sex != \"0\"'> and s_sex = #{sex}  </if> "
            // #{} 根据类型转换   s_sex= '男'  ${}不转换值直接显示  like = '%男%'
            + " and s_name like '%${sname}%'  "
            +  " <if test=\"birthday != null\"> and s_birth > #{birthday}   </if>  "
            + "      </script>")
    List<Student> findByCondition(Student stu);

    @Delete(" DELETE FROM mz_student WHERE s_id = #{id} ")
    int deleteById(@Param("id") Integer id);

    @Select(" select s_id id, s_name sname, s_birth birthday, s_sex sex, version from mz_student where s_id = #{id} ")
    Student findById(Integer id);

    @Select(" select s_id id, s_name sname, s_birth birthday, s_sex sex, version from mz_student where s_id = #{id} and version = #{version} for update ")
    Student findByIdVersion(Student stu);

    @Insert(" "
            + " update mz_student set s_name = #{sname}, s_birth = #{birthday}, "
            + " s_sex = #{sex} , version = version + 1 where s_id = #{id} ")
    int update(Student stu);

}
